<?php
	session_start();
	mysql_connect("localhost", "sapmenet_admin", "a1s2d3f4g5h6j7") or die ("Problem with datebase");
	mysql_select_db("sapmenet_users");
	$you = $_SESSION['JID'];
	if (isset($_POST['opened']))
	{
	$opened = $_POST['opened'];
	echo"<link rel = 'stylesheet' type = 'text/css' href = 'friendshipsRequestsStyle.css'>";
	$show = mysql_query("SELECT DISTINCT chat.from, concat(users.FirstName, ' ', users.LastName) AS fullName, users.id FROM chat JOIN users ON chat.from = users.id WHERE chat.seen=0 AND chat.from NOT LIKE '".$opened."' AND chat.to={$you}");
	while ($res=mysql_fetch_array($show, MYSQL_NUM))
	{
		echo ("<div class = 'singleNotificationTab' id = '".$res[2]."' onclick = 'zaek(".$res[2].")' title = '".$res[1]."'>".$res[1]." sent you a message.</div>");
	}
	echo"<script>
		function zaek(curche)
		{
			$.post('showMessages.php', {ot : curche}, function(data)
			{
				$('.messagesField').html(data);
				$('.messagesField').scrollTop(9000);
			});
			$.post('getUserName.php', {bau : curche}, function(data)
			{
				$('#interlocutorHeaderNameText').html(data);
			});
			$('.chatWindowHeader').attr('id', curche);
			$.post('showProfilePicture.php', {picture:curche}, function(data)
			{
				$('.chatPfffPicture').html(data);
			});
			$('.singleChatDialog').show('explode');
			$('.messagesField').scrollTop(9000);
			$('#newsDialog').hide('explode');
		}
	</script>
	";
	}
	
?>